@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <button class="btn" onclick="history.go(-1);">
                            <span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>
                        </button>
                        生命密码管理</div>

                    <div class="panel-body">
                        @if (session('status'))
                            <div class="alert alert-success">
                                {{ session('status') }}
                            </div>
                        @endif
                        {{--查询--}}
                         <div class="row">
                             <div class="col-md-8">
                                 <form class="form-inline">
                                     {{ csrf_field() }}

                                     <div class="form-group">
                                         <label for="exampleInputName2">生命密码</label>
                                         <input type="text" class="form-control" name="main_number" id="main_number" value="{{ $condition['main_number'] ?? '' }}" placeholder="1">
                                     </div>

                                     <button type="submit" class="btn btn-primary">查询</button>
                                 </form>
                             </div>
                             {{--菜单--}}

                             <div class="col-md-4">
                                     <a href="{{ route('talent_create') }}" type="button" class="btn btn-primary">新增</a>
                             </div>

                         </div>

                        {{--列表--}}
                        <div class="list">
                            <table class="table table-hover">
                                <tr>
                                    <th>生命数字</th>
                                    <th>一句话描述</th>
                                    <th>详细描述</th>
                                    <th>职业方向</th>
                                    <th>引导策略</th>
                                    <th>缺数性格</th>
                                    <th>多数性格</th>
                                    <th>操作</th>
                                </tr>

                                @foreach($list->items() as $item)
                                <tr >
                                    <td>{{ $item->main_number }}</td>
                                    <td>{{ str_limit($item->brief, $limit = 20, $end = '...')}}</td>
                                    <td>{{ str_limit($item->description, $limit = 20, $end = '...')}}</td>
                                    <td>{{ str_limit($item->career_path, $limit = 20, $end = '...')}}</td>
                                    <td>{{ str_limit($item->guiding_strategy, $limit = 20, $end = '...')}}</td>
                                    <td>{{ str_limit($item->little_less, $limit = 20, $end = '...')}}</td>
                                    <td>{{ str_limit($item->little_more, $limit = 20, $end = '...')}}</td>
                                    <td style="min-width:180px; ">
                                        <a href="{{ route('talent_relation', ['id'=>$item->id]) }}"  class="btn btn-default btn-sm">设置相处技巧</a>
                                        <a href="{{ route('talent_show', ['id' => $item->id ]) }}" class="btn btn-info btn-sm">详情</a>
                                        <a href="{{ route('talent_edit', ['id' => $item->id ]) }}" class="btn btn-success btn-sm">修改</a>
                                        <a href="javascript:void(0);" onclick="deleteItem('{{ route('talent_delete', ['id'=>$item->id]) }}');" class="btn btn-danger btn-sm">删除</a>
                                    </td>

                                </tr>
                                @endforeach
                            </table>
                        </div>

                        {{--分页--}}
                            {!! $list->links() !!}

                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script type="text/javascript">

        function deleteItem( route) {
            if(confirm("确定删除么？")){
                $.ajax({
                    url: route ,
                    type:'POST', //GET
                    async:true,    //或false,是否异步
                    // data:{
                    //     name:'yang',age:25
                    // },
                    headers: {
                        'X-CSRF-TOKEN': $('input[name="_token"]').val()
                    },
                    timeout:5000,    //超时时间
                    dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    beforeSend:function(xhr){
                        console.log(xhr)
                        console.log('发送前')
                    },
                    success:function(data,textStatus,jqXHR){
                        console.log(data)
                        console.log(textStatus)
                        console.log(jqXHR)
                        if(!data.errors){
                            alert("删除成功！");
                            location.reload();
                        }else {
                            alert("删除失败！");
                        }
                    },
                    error:function(xhr,textStatus){
                        console.log('错误')
                        console.log(xhr)
                        console.log(textStatus)
                    },
                    complete:function(){
                        console.log('结束')
                    }
                })
            }

        }


    </script>
@endsection
